package com.shqcjd.generalplatformprojectclient.ui.presenter;

import com.shqcjd.generalplatformprojectclient.api.ApiService;
import com.shqcjd.generalplatformprojectclient.helper.rxjavahelper.RxObserver;
import com.shqcjd.generalplatformprojectclient.helper.rxjavahelper.RxSchedulersHelper;
import com.shqcjd.generalplatformprojectclient.model.ResponseData;
import com.shqcjd.generalplatformprojectclient.model.pojo.GuidanceMsgBean;
import com.shqcjd.generalplatformprojectclient.ui.base.BasePresenter;
import com.shqcjd.generalplatformprojectclient.ui.view.FileListView;

import java.util.List;

import io.reactivex.disposables.Disposable;

/**
 * Created by sy on 2018/12/27.
 */

public class FileListPresenter extends BasePresenter<FileListView> {

    public void getFileListDate(String id){
        ApiService.getGuideMsgList(id)
                .compose(RxSchedulersHelper.io_main())
                .subscribe(new RxObserver<ResponseData<List<GuidanceMsgBean>>>() {
                    @Override
                    public void _onSubscribe(Disposable d) {
                        getView().showProgress("加载中..");
                    }

                    @Override
                    public void _onNext(ResponseData<List<GuidanceMsgBean>> responseData) {
                        if (responseData.code == 0) {
                            getView().getRefreshDataSuccess(responseData.data);
                        } else {
                            getView().getDataError(responseData.message);
                        }

                    }

                    @Override
                    public void _onError(String errorMessage) {
                        getView().getDataError(errorMessage);
                        getView().hideProgress();
                    }

                    @Override
                    public void _onComplete() {
                        getView().hideProgress();
                    }
                });
    }
}
